// merchantManage.js
const app = getApp()
const util = require("../../utils/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: {
      searchAddShow: false,
      BtnTxt: '',
      searchTip: '输入店铺名称搜索',
      searchValue: '',
    },
    list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.shoplist();    
    wx.stopPullDownRefresh()
  },
  searchChange: function (event) {
    var detail = 'search.searchValue'
    this.setData({
      [detail]: event.detail
    })
  },
  // 搜索
  onSearch: function () {
    this.shoplist('search');
  },
  // 获取列表
  shoplist: function (type) {
    var that = this;
    if (type == 'search') {
      that.setData({ list: [] })
    }
    var data = { input: that.data.search.searchValue };
    app.post("shop/shop", data).then((res) => {
      if (res.code == 200) {
        that.setData({
          list: res.list
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);//错误提示信息
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      BtnTxt:'' 
    })
    this.onLoad();
  }
})